//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include <RenderLibServer.h>
////////////////////////////////////////////////////////////////////////////
//                              Blit relatives                            //
////////////////////////////////////////////////////////////////////////////

#ifdef __cplusplus
extern "C" {
#endif

Void RGB24StretchBlit2RGB24WMMX(Pixel* pSrc, Pixel* pDst,
                                    Int32 srcPitch, Int32 dstPitch,
                                    Int32 srcWidth, Int32 srcHeight,
                                    Int32 dstWidth, Int32 dstHeight,
                                    UInt32 xrIntFloat_16,
                                    UInt32 yrIntFloat_16,
                                    UInt32 interpolation);

Void RGB24StretchBlend2RGB24WMMX(Pixel* pSrc, Pixel* pDst,
                                Int32 srcPitch, Int32 dstPitch,
                                Int32 srcWidth, Int32 srcHeight,
                                Int32 dstWidth, Int32 dstHeight,
                                UInt32 xrIntFloat_16,
                                UInt32 yrIntFloat_16,
                                UInt32 interpolation,
                                UInt8 srcOpacity);

Void RGB24StretchBlit2ARGB32WMMX(Pixel* pSrc, Pixel* pDst,
                                Int32 srcPitch, Int32 dstPitch,
                                Int32 srcWidth, Int32 srcHeight,
                                Int32 dstWidth, Int32 dstHeight,
                                UInt32 xrIntFloat_16,
                                UInt32 yrIntFloat_16,
                                UInt32 interpolation);

Void RGB24StretchBlend2ARGB32WMMX(Pixel* pSrc, Pixel* pDst,
                                Int32 srcPitch, Int32 dstPitch,
                                Int32 srcWidth, Int32 srcHeight,
                                Int32 dstWidth, Int32 dstHeight,
                                UInt32 xrIntFloat_16,
                                UInt32 yrIntFloat_16,
                                UInt32 interpolation,
                                UInt8 srcOpacity);

Void ARGB32StretchBlit2RGB24WMMX(Pixel* pSrc, Pixel* pDst,
                                Int32 srcPitch, Int32 dstPitch,
                                Int32 srcWidth, Int32 srcHeight,
                                Int32 dstWidth, Int32 dstHeight,
                                UInt32 xrIntFloat_16,
                                UInt32 yrIntFloat_16,
                                UInt32 interpolation);

Void ARGB32StretchBlend2RGB24WMMX(Pixel* pSrc, Pixel* pDst,
                                Int32 srcPitch, Int32 dstPitch,
                                Int32 srcWidth, Int32 srcHeight,
                                Int32 dstWidth, Int32 dstHeight,
                                UInt32 xrIntFloat_16,
                                UInt32 yrIntFloat_16,
                                UInt32 interpolation,
                                UInt8 srcOpacity);

Void ARGB32StretchBlit2ARGB32WMMX(Pixel* pSrc, Pixel* pDst,
                                Int32 srcPitch, Int32 dstPitch,
                                Int32 srcWidth, Int32 srcHeight,
                                Int32 dstWidth, Int32 dstHeight,
                                UInt32 xrIntFloat_16,
                                UInt32 yrIntFloat_16,
                                UInt32 interpolation);

Void ARGB32StretchBlend2ARGB32WMMX(Pixel* pSrc, Pixel* pDst,
                                Int32 srcPitch, Int32 dstPitch,
                                Int32 srcWidth, Int32 srcHeight,
                                Int32 dstWidth, Int32 dstHeight,
                                UInt32 xrIntFloat_16,
                                UInt32 yrIntFloat_16,
                                UInt32 interpolation,
                                UInt8 srcOpacity);

Void A8StretchBlit2ARGB32WMMX(UInt8* pSrc, Pixel* pDst,
                                Int32 srcPitch, Int32 dstPitch,
                                Int32 srcWidth, Int32 srcHeight,
                                Int32 dstWidth, Int32 dstHeight,
                                UInt32 xrIntFloat_16,
                                UInt32 yrIntFloat_16,
                                UInt32 interpolation,
                                Color srcColor);

Void A8StretchBlend2ARGB32WMMX(UInt8* pSrc, Pixel* pDst,
                                Int32 srcPitch, Int32 dstPitch,
                                Int32 srcWidth, Int32 srcHeight,
                                Int32 dstWidth, Int32 dstHeight,
                                UInt32 xrIntFloat_16,
                                UInt32 yrIntFloat_16,
                                UInt32 interpolation,
                                Color srcColor, UInt8 srcOpacity);

Void A8StretchBlit2RGB24WMMX(UInt8* pSrc, Pixel* pDst,
                                Int32 srcPitch, Int32 dstPitch,
                                Int32 srcWidth, Int32 srcHeight,
                                Int32 dstWidth, Int32 dstHeight,
                                UInt32 xrIntFloat_16,
                                UInt32 yrIntFloat_16,
                                UInt32 interpolation,
                                Color srcColor);

Void A8StretchBlend2RGB24WMMX(UInt8* pSrc, Pixel* pDst,
                                Int32 srcPitch, Int32 dstPitch,
                                Int32 srcWidth, Int32 srcHeight,
                                Int32 dstWidth, Int32 dstHeight,
                                UInt32 xrIntFloat_16,
                                UInt32 yrIntFloat_16,
                                UInt32 interpolation,
                                Color srcColor, UInt8 srcOpacity);

Void RECT888To565WMMX(BitmapBufInfo* src, BitmapBufInfo* dst);
Void RECT888To565FLIPWMMX(BitmapBufInfo* src, BitmapBufInfo* dst);
Void RECT888To565RCWWMMX(BitmapBufInfo* src, BitmapBufInfo* dst);
Void RECT888To565RCCWWMMX(BitmapBufInfo* src, BitmapBufInfo* dst);

Void RECT888To666WMMX(BitmapBufInfo* src, BitmapBufInfo* dst);
Void RECT888To666FLIPWMMX(BitmapBufInfo* src, BitmapBufInfo* dst);
Void RECT888To666RCWWMMX(BitmapBufInfo* src, BitmapBufInfo* dst);
Void RECT888To666RCCWWMMX(BitmapBufInfo* src, BitmapBufInfo* dst);

#ifdef __cplusplus
}
#endif
////////////////////////////////////////////////////////////////////////////
//                          Stretch Blit relatives                        //
////////////////////////////////////////////////////////////////////////////

Void RGB24StretchBlit2RGB24(Address dst, Int32 dstX, Int32 dstY,
                            Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                            Address src, Int32 srcX, Int32 srcY,
                            Int32 srcWidth, Int32 srcHeight, Int32 srcPitch,
                            UInt8 srcOpacity,
                            UInt8 interpolation)
{
    assert(dst && src);
    assert(srcWidth > 0 && srcHeight > 0);
    assert(dstWidth > 0 && dstHeight > 0);
    assert(dstX >= 0 && dstY >= 0 && srcX >= 0 && srcY >= 0);

    UInt32 xrIntFloat_16;
    UInt32 yrIntFloat_16;
    ((UInt8*&)src) += srcPitch * srcY + (srcX<<2);
    ((UInt8*&)dst) += dstPitch * dstY + (dstX<<2);

    if (interpolation) {
        xrIntFloat_16 = ((srcWidth - 1)<<16) / dstWidth;
        yrIntFloat_16 = ((srcHeight - 1)<<16) / dstHeight;
    }
    else {
        xrIntFloat_16 = (srcWidth<<16) / dstWidth;
        yrIntFloat_16 = (srcHeight<<16) / dstHeight;
    }

    if (255 == srcOpacity) {
        RGB24StretchBlit2RGB24WMMX((Pixel*)src, (Pixel*)dst,
                                    srcPitch, dstPitch,
                                    srcWidth, srcHeight,
                                    dstWidth, dstHeight,
                                    xrIntFloat_16, yrIntFloat_16,
                                    interpolation);
    }
    else if (0 == srcOpacity) {
    }
    else {
        RGB24StretchBlend2RGB24WMMX((Pixel*)src, (Pixel*)dst,
                                    srcPitch, dstPitch,
                                    srcWidth, srcHeight,
                                    dstWidth, dstHeight,
                                    xrIntFloat_16, yrIntFloat_16,
                                    interpolation,
                                    srcOpacity);
    }
}

Void RGB24StretchBlit2ARGB32(Address dst, Int32 dstX, Int32 dstY,
                            Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                            Address src, Int32 srcX, Int32 srcY,
                            Int32 srcWidth, Int32 srcHeight, Int32 srcPitch,
                            UInt8 srcOpacity,
                            UInt8 interpolation)
{
    assert(dst && src);
    assert(srcWidth > 0 && srcHeight > 0);
    assert(dstWidth > 0 && dstHeight > 0);
    assert(dstX >= 0 && dstY >= 0 && srcX >= 0 && srcY >= 0);

    UInt32 xrIntFloat_16;
    UInt32 yrIntFloat_16;
    ((UInt8*&)src) += srcPitch * srcY + (srcX<<2);
    ((UInt8*&)dst) += dstPitch * dstY + (dstX<<2);

    if (interpolation) {
        xrIntFloat_16 = ((srcWidth - 1)<<16) / dstWidth;
        yrIntFloat_16 = ((srcHeight - 1)<<16) / dstHeight;
    }
    else {
        xrIntFloat_16 = (srcWidth<<16) / dstWidth;
        yrIntFloat_16 = (srcHeight<<16) / dstHeight;
    }

    if (255 == srcOpacity) {
        RGB24StretchBlit2ARGB32WMMX((Pixel*)src, (Pixel*)dst,
                                    srcPitch, dstPitch,
                                    srcWidth, srcHeight,
                                    dstWidth, dstHeight,
                                    xrIntFloat_16, yrIntFloat_16,
                                    interpolation);
    }
    else if (0 == srcOpacity) {
    }
    else {
        RGB24StretchBlend2ARGB32WMMX((Pixel*)src, (Pixel*)dst,
                                    srcPitch, dstPitch,
                                    srcWidth, srcHeight,
                                    dstWidth, dstHeight,
                                    xrIntFloat_16, yrIntFloat_16,
                                    interpolation,
                                    srcOpacity);
    }
}

Void ARGB32StretchBlit2RGB24(Address dst, Int32 dstX, Int32 dstY,
                            Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                            Address src, Int32 srcX, Int32 srcY,
                            Int32 srcWidth, Int32 srcHeight, Int32 srcPitch,
                            UInt8 srcOpacity,
                            UInt8 interpolation)
{
    assert(dst && src);
    assert(srcWidth > 0 && srcHeight > 0);
    assert(dstWidth > 0 && dstHeight > 0);
    assert(dstX >= 0 && dstY >= 0 && srcX >= 0 && srcY >= 0);

    UInt32 xrIntFloat_16;
    UInt32 yrIntFloat_16;
    ((UInt8*&)src) += srcPitch * srcY + (srcX<<2);
    ((UInt8*&)dst) += dstPitch * dstY + (dstX<<2);

    if (interpolation) {
        xrIntFloat_16 = ((srcWidth - 1)<<16) / dstWidth;
        yrIntFloat_16 = ((srcHeight - 1)<<16) / dstHeight;
    }
    else {
        xrIntFloat_16 = (srcWidth<<16) / dstWidth;
        yrIntFloat_16 = (srcHeight<<16) / dstHeight ;
    }

    if (255 == srcOpacity) {
        ARGB32StretchBlit2RGB24WMMX((Pixel*)src, (Pixel*)dst,
                                    srcPitch, dstPitch,
                                    srcWidth, srcHeight,
                                    dstWidth, dstHeight,
                                    xrIntFloat_16, yrIntFloat_16,
                                    interpolation);
    }
    else if (0 == srcOpacity) {
    }
    else {
        ARGB32StretchBlend2RGB24WMMX((Pixel*)src, (Pixel*)dst,
                                    srcPitch, dstPitch,
                                    srcWidth, srcHeight,
                                    dstWidth, dstHeight,
                                    xrIntFloat_16, yrIntFloat_16,
                                    interpolation,
                                    srcOpacity);
    }
}

Void ARGB32StretchBlit2ARGB32(Address dst, Int32 dstX, Int32 dstY,
                            Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                            Address src, Int32 srcX, Int32 srcY,
                            Int32 srcWidth, Int32 srcHeight, Int32 srcPitch,
                            UInt8 srcOpacity,
                            UInt8 interpolation)
{
    assert(dst && src);
    assert(srcWidth > 0 && srcHeight > 0);
    assert(dstWidth > 0 && dstHeight > 0);
    assert(dstX >= 0 && dstY >= 0 && srcX >= 0 && srcY >= 0);

    UInt32 xrIntFloat_16;
    UInt32 yrIntFloat_16;
    ((UInt8*&)src) += srcPitch * srcY + (srcX<<2);
    ((UInt8*&)dst) += dstPitch * dstY + (dstX<<2);

    if (interpolation) {
        xrIntFloat_16 = ((srcWidth - 1)<<16) / dstWidth;
        yrIntFloat_16 = ((srcHeight - 1)<<16) / dstHeight;
    }
    else {
        xrIntFloat_16 = (srcWidth<<16) / dstWidth;
        yrIntFloat_16 = (srcHeight<<16) / dstHeight;
    }

    if (255 == srcOpacity) {
        ARGB32StretchBlit2ARGB32WMMX((Pixel*)src, (Pixel*)dst,
                                    srcPitch, dstPitch,
                                    srcWidth, srcHeight,
                                    dstWidth, dstHeight,
                                    xrIntFloat_16, yrIntFloat_16,
                                    interpolation);
    }
    else if (0 == srcOpacity) {
    }
    else {
        ARGB32StretchBlend2ARGB32WMMX((Pixel*)src, (Pixel*)dst,
                                    srcPitch, dstPitch,
                                    srcWidth, srcHeight,
                                    dstWidth, dstHeight,
                                    xrIntFloat_16, yrIntFloat_16,
                                    interpolation,
                                    srcOpacity);
    }
}

Void A8StretchBlit2ARGB32(Address dst, Int32 dstX, Int32 dstY,
                        Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                        Address src, Int32 srcX, Int32 srcY,
                        Int32 srcWidth, Int32 srcHeight, Int32 srcPitch,
                        UInt8 srcOpacity,
                        UInt8 interpolation,
                        Color srcColor)
{
    assert(dst && src);
    assert(dstWidth > 0 && dstHeight > 0);
    assert(srcWidth > 0 && srcHeight > 0);
    assert(dstX >= 0 && dstY >= 0 && srcX >= 0 && srcY >= 0);

    UInt32 xrIntFloat_16;
    UInt32 yrIntFloat_16;
    ((UInt8*&)src) += srcPitch * srcY + srcX;
    ((UInt8*&)dst) += dstPitch * dstY + (dstX<<2);

    if (interpolation) {
        xrIntFloat_16 = ((srcWidth - 1)<<16) / dstWidth;
        yrIntFloat_16 = ((srcHeight - 1)<<16) / dstHeight;
    }
    else {
        xrIntFloat_16 = (srcWidth<<16) / dstWidth;
        yrIntFloat_16 = (srcHeight<<16) / dstHeight;
    }

    if (255 == srcOpacity) {
        A8StretchBlit2ARGB32WMMX((UInt8*)src, (Pixel*)dst,
                                    srcPitch, dstPitch,
                                    srcWidth, srcHeight,
                                    dstWidth, dstHeight,
                                    xrIntFloat_16, yrIntFloat_16,
                                    interpolation, srcColor);
    }
    else if (0 == srcOpacity) {
    }
    else {
        A8StretchBlend2ARGB32WMMX((UInt8*)src, (Pixel*)dst,
                                    srcPitch, dstPitch,
                                    srcWidth, srcHeight,
                                    dstWidth, dstHeight,
                                    xrIntFloat_16, yrIntFloat_16,
                                    interpolation,
                                    srcColor, srcOpacity);
    }
}

Void A8StretchBlit2RGB24(Address dst, Int32 dstX, Int32 dstY,
                        Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                        Address src, Int32 srcX, Int32 srcY,
                        Int32 srcWidth, Int32 srcHeight, Int32 srcPitch,
                        UInt8 srcOpacity,
                        UInt8 interpolation,
                        Color srcColor)
{
    assert(dst && src);
    assert(srcWidth > 0 && srcHeight > 0);
    assert(dstWidth > 0 && dstHeight > 0);
    assert(dstX >= 0 && dstY >= 0 && srcX >= 0 && srcY >= 0);

    UInt32 xrIntFloat_16;
    UInt32 yrIntFloat_16;
    ((UInt8*&)src) += srcPitch * srcY + srcX;
    ((UInt8*&)dst) += dstPitch * dstY + (dstX<<2);

    if (interpolation) {
        xrIntFloat_16 = ((srcWidth - 1)<<16) / dstWidth;
        yrIntFloat_16 = ((srcHeight - 1)<<16) / dstHeight;
    }
    else {
        xrIntFloat_16 = (srcWidth<<16) / dstWidth;
        yrIntFloat_16 = (srcHeight<<16) / dstHeight;
    }

    if (255 == srcOpacity) {
        A8StretchBlit2RGB24WMMX((UInt8*)src, (Pixel*)dst,
                                    srcPitch, dstPitch,
                                    srcWidth, srcHeight,
                                    dstWidth, dstHeight,
                                    xrIntFloat_16, yrIntFloat_16,
                                    interpolation, srcColor);
    }
    else if (0 == srcOpacity) {
    }
    else {
        A8StretchBlend2RGB24WMMX((UInt8*)src, (Pixel*)dst,
                                    srcPitch, dstPitch,
                                    srcWidth, srcHeight,
                                    dstWidth, dstHeight,
                                    xrIntFloat_16, yrIntFloat_16,
                                    interpolation,
                                    srcColor, srcOpacity);
    }
}

Void RGB24ToRGB565(
                Address Dst, Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                Address Src, Int32 srcPitch,
                Int32 x, Int32 y, Int32 width, Int32 height,
                Int32 orientation)
{
    assert(Dst && Src);
    assert(dstWidth > 0 && dstHeight > 0);
    assert(dstPitch > 0 && srcPitch > 0);
    assert(x >= 0 && y >= 0 && width > 0 && height >= 0);
    assert(orientation>=0 && orientation < 4);

    BitmapBufInfo dst = {Dst, dstWidth, dstHeight, dstPitch, 2, 16};
    BitmapBufInfo src = {Src, dstHeight, dstWidth, srcPitch, 2, 32};
    Region region = {x, y, x + width, y + height};

    switch (orientation) {
        case 0:
            ((char*&)src.address) += (region.left<<2) + region.top * src.pitch;
            src.width = region.right - region.left;
            src.height = region.bottom - region.top;
            ((char*&)dst.address) += (region.left<<1) + region.top * dst.pitch;
            RECT888To565WMMX(&src, &dst);
            break;
        case 1:
            ((char*&)src.address) += (region.left<<2) + region.top * src.pitch;
            src.width = region.right - region.left;
            src.height = region.bottom - region.top;
            ((char*&)dst.address) += ((dst.width - region.bottom)<<1)
                    + region.left * dst.pitch;
            RECT888To565RCWWMMX(&src, &dst);
            break;
        case 2:
            ((char*&)src.address) += (region.left<<2) + region.top * src.pitch;
            src.width = region.right - region.left;
            src.height = region.bottom - region.top;
            ((char*&)dst.address) += ((dst.width - region.left)<<1)
                     + (dst.height - region.top - 1) * dst.pitch;
            RECT888To565FLIPWMMX(&src, &dst);
            break;
        case 3:
            ((char*&)src.address) += (region.left<<2) + region.top * src.pitch;
            src.width = region.right - region.left;
            src.height = region.bottom - region.top;
            ((char*&)dst.address) += (region.top<<1)
                     + (dst.height - region.left - 1) * dst.pitch;
            RECT888To565RCCWWMMX(&src, &dst);
            break;
    }
}

Void RGB24ToRGB666(
                Address Dst, Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                Address Src, Int32 srcPitch,
                Int32 x, Int32 y, Int32 width, Int32 height,
                Int32 orientation)
{
    assert(Dst && Src);
    assert(dstWidth > 0 && dstHeight > 0);
    assert(dstPitch > 0 && srcPitch > 0);
    assert(x >= 0 && y >= 0 && width > 0 && height >= 0);
    assert(orientation>=0 && orientation < 4);

    BitmapBufInfo dst = {Dst, dstWidth, dstHeight, dstPitch, 2, 32};
    BitmapBufInfo src = {Src, dstHeight, dstWidth, srcPitch, 2, 32};
    Region region = {x, y, x + width, y + height};

    switch (orientation) {
        case 0:
            ((char*&)src.address) += (region.left<<2) + region.top * src.pitch;
            src.width = region.right - region.left;
            src.height = region.bottom - region.top;
            ((char*&)dst.address) += (region.left<<2) + region.top * dst.pitch;
            RECT888To666WMMX(&src, &dst);
            break;
        case 1:
            ((char*&)src.address) += (region.left<<2) + region.top * src.pitch;
            src.width = region.right - region.left;
            src.height = region.bottom - region.top;
            ((char*&)dst.address) += ((dst.width - region.bottom)<<2)
                    + region.left * dst.pitch;
            RECT888To666RCWWMMX(&src, &dst);
            break;
        case 2:
            ((char*&)src.address) += (region.left<<2) + region.top * src.pitch;
            src.width = region.right - region.left;
            src.height = region.bottom - region.top;
            ((char*&)dst.address) += ((dst.width - region.left)<<2)
                     + (dst.height - region.top - 1) * dst.pitch;
            RECT888To666FLIPWMMX(&src, &dst);
            break;
        case 3:
            ((char*&)src.address) += (region.left<<2) + region.top * src.pitch;
            src.width = region.right - region.left;
            src.height = region.bottom - region.top;
            ((char*&)dst.address) += (region.top<<2)
                     + (dst.height - region.left - 1) * dst.pitch;
            RECT888To666RCCWWMMX(&src, &dst);
            break;
        }
}

Void RGB24ToRGB888(
                Address dst, Int32 dstWidth, Int32 dstHeight, Int32 dstPitch,
                Address src, Int32 srcPitch,
                Int32 x, Int32 y, Int32 width, Int32 height,
                Int32 orientation)
{
    assert(dst && src);
    assert(dstWidth > 0 && dstHeight > 0);
    assert(dstPitch > 0 && srcPitch > 0);
    assert(x >= 0 && y >= 0 && width > 0 && height >= 0);
    assert(orientation>=0 && orientation < 4);

    src += y * srcPitch + (x<<2);

    switch (orientation) {
        case 0:
            dst += y * dstPitch + (x<<2);
            while (height--) {
                ScanLineRGB24ToRGB24(dst, src, width);
                dst += dstPitch;
                src += srcPitch;
            }
            break;

        case 1:
            dst += x * dstPitch + ((dstWidth - y - 1)<<2);
            while (height--) {
                ScanLineRECT888To888RCW(dst, src, width, dstPitch);
                dst = (Address)((UInt32*)dst - 1);
                src += srcPitch;
            }
            break;

        case 2:
            dst += (dstHeight - y - 1) * dstPitch + ((dstWidth - x)<<2);
            while (height--) {
                ScanLineRECT888To888FLIP(dst, src, width);
                dst -= dstPitch;
                src += srcPitch;
            }
            break;

        case 3:
            dst += (dstHeight - x - 1) * dstPitch + (y<<2);
            while (height--) {
                ScanLineRECT888To888RCCW(dst, src, width, dstPitch);
                dst = (Address)((UInt32*)dst + 1);
                src += srcPitch;
            }
            break;
    }
}

Void RGB24Blit2RGB24WithOrientation(
                Address dst, Int32 dstX, Int32 dstY, Int32 dstPitch,
                Address src, Int32 srcX, Int32 srcY, Int32 width, Int32 height, Int32 srcPitch,
                Int32 orientation)
{
    assert(dst && src);
    assert(width > 0 && height >= 0);
    assert(dstPitch > 0 && srcPitch > 0);
    assert(dstX >= 0 && dstY >= 0 && srcX >= 0 && srcY >= 0);

    src += srcY * srcPitch + (srcX<<2);
    dst += dstY * dstPitch + (dstX<<2);

    switch (orientation) {
        case 0:
            while (height--) {
                ScanLineRGB24ToRGB24(dst, src, width);
                dst += dstPitch;
                src += srcPitch;
            }
            break;

        case 1:
            while (height--) {
                ScanLineRECT888To888RCW(dst, src, width, dstPitch);
                dst = (Address)((UInt32*)dst - 1);
                src += srcPitch;
            }
            break;

        case 2:
            while (height--) {
                ScanLineRECT888To888FLIP(dst, src, width);
                dst -= dstPitch;
                src += srcPitch;
            }
            break;

        case 3:
            while (height--) {
                ScanLineRECT888To888RCCW(dst, src, width, dstPitch);
                dst = (Address)((UInt32*)dst + 1);
                src += srcPitch;
            }
            break;
    }
}





Void WarpPerspective_8u_C4A(
            const BitmapBufInfo& Src, const BitmapBufInfo& Dst,
            Int32 nWidth, Int32 nLHeight, Int32 nRHeight)
{
    _WARPPERSP para;

    para.SrcH = Src.height>>1;
    para.DstW = nWidth;
    para.DstHL = nLHeight>>1;
    para.DstHR = nRHeight>>1;
    para.SrcXD16 = ((((Src.width-1)<<16))/(para.DstW-1));
    para.SrcYD16 = ((((para.SrcH-1)<<16))/(para.DstHL-1));

    para.Dst_Pitch = Dst.pitch;
    para.Src_Pitch = Src.pitch;

    para.pSrc = (Pixel*)(Src.address + Src.pitch * para.SrcH);

    if (para.DstHL >= para.DstHR) {
        para.pDst = (Pixel*)(Dst.address + Dst.pitch * para.DstHL);
        para.DstHD16 = (para.DstHL<<16) - (((para.DstHR + para.DstHL * (para.DstW - 1)) <<16) / para.DstW);
        WarpPerspectiveLWMMX(para);
    }
    else {
        para.pDst = (Pixel*)(Dst.address + Dst.pitch * para.DstHR);
        para.DstHD16 = (para.DstHR<<16) - (((para.DstHL + para.DstHR * (para.DstW - 1)) <<16) / para.DstW);
        WarpPerspectiveRWMMX(para);
    }

}

Void WarpPerspectiveH_8u_C4A(
            const BitmapBufInfo& Src, const BitmapBufInfo& Dst,
            Int32 nWidthT, Int32 nWidthD, Int32 nHeight)
{
    _WARPPERSPH para;

    para.SrcW = Src.width>>1;
    para.DstH = nHeight;
    para.DstWT = nWidthT>>1;
    para.DstWD = nWidthD>>1;
    para.SrcYD16 = (((Src.height-1)<<16))/(para.DstH-1);
    para.SrcXD16 = (((para.SrcW-1)<<16))/(para.DstWT-1);

    para.Dst_Pitch = Dst.pitch;
    para.Src_Pitch = Src.pitch;

    para.pSrc = (Pixel*)Src.address + para.SrcW;

    if (para.DstWT >= para.DstWD) {
        para.pDst = (Pixel*)Dst.address + para.DstWT;
        para.DstWD16 = (para.DstWT<<16) - (((para.DstWD + para.DstWT * (para.DstH - 1)) <<16) / para.DstH);
        WarpPerspectiveTWMMX(para);
    }
    else {
        para.pDst = (Pixel*)Dst.address + para.DstWD;
        para.DstWD16 = (para.DstWD<<16) - (((para.DstWT + para.DstWD * (para.DstH - 1)) <<16) / para.DstH);
        WarpPerspectiveDWMMX(para);
    }

}

Void ShearBilinear_8u_C4A(
            const BitmapBufInfo& Src, const BitmapBufInfo& Dst,
            Int32 offset)
{
    if ((abs(offset)+1)>Dst.width)
        return;

    _SHEAR shear;

    shear.pSrc = (Pixel*)Src.address;
    shear.pDst = (Pixel*)Dst.address;

    shear.SrcW = Src.width;
    shear.SrcH = Src.height;
    shear.DstW = Dst.width - abs(offset);
    shear.DstH =  Dst.height;

    shear.SrcXD16 = ((((shear.SrcW-1)<<16))/(shear.DstW-1));
    shear.SrcYD16 = ((((shear.SrcH-1)<<16))/(shear.DstH-1));
    shear.DstSX16 = (abs(offset)<<16)/shear.DstH;

    shear.Dst_Pitch = Dst.pitch;
    shear.Src_Pitch = Src.pitch;
    shear.offset = abs(offset);

    if (offset>=0) {
        shear.Dst_SX16 = 0;
        ShearBilinearP_8u_C4A(shear);

    }
    else {
        shear.Dst_SX16 = abs(offset)<<16;
        ShearBilinearM_8u_C4A(shear);
    }
}

Void CurveBilinear_8u_C4A(
        const BitmapBufInfo& Src, const BitmapBufInfo& Dst,
        Int32* aSampleX16, Int32 width)
{

    _CURVE curve;

    curve.pSrc = (Pixel*)Src.address;
    curve.pDst = (Pixel*)Dst.address;

    curve.SrcW = Src.width;
    curve.SrcH = Src.height;
    curve.DstW = Dst.width;
    curve.DstH = Dst.height;

    curve.SrcXD16 = (((curve.SrcW-1)<<16))/(curve.DstW)+1;
    curve.SrcYD16 = (((curve.SrcH-1)<<16))/(curve.DstH)+1;
    curve.aSampleX16 = aSampleX16;
    curve.Dst_SX16 = aSampleX16[0];

    curve.Dst_Pitch = Dst.pitch;
    curve.Src_Pitch = Src.pitch;
    curve.InnerWidth = width;

    CurveBilinearWMMX_8u_C4A(curve);
}

Void DrawAAPolygon(
            Point * leftVertexList, Int32 LEdgeNum,
            Point * rightVertexList, Int32 REdgeNum,
            const BitmapBufInfo * srcImg, const BitmapBufInfo * dstImg,
            Int32 level)
{
    Int32 startY = leftVertexList[0].y;
    Int32 height = leftVertexList[LEdgeNum].y - leftVertexList[0].y;
    ScanLineList * scanlinelist = new ScanLineList[height+2];

    Int32 i;
    for (i=0;i<LEdgeNum;i++) {
        ScanLeftAAEdge(leftVertexList[i], leftVertexList[i+1], scanlinelist, startY, height, srcImg, dstImg);
    }
    for (i=0;i<REdgeNum;i++) {
        ScanRightAAEdge(rightVertexList[i], rightVertexList[i+1], scanlinelist, startY, height, srcImg, dstImg);
    }

    _POLYFILL pfill;

    pfill.pSrc = (UInt8*)srcImg->address;
    pfill.pDst = (UInt8*)dstImg->address;
    pfill.nSrcPitch = dstImg->pitch;
    pfill.nDstPitch = dstImg->pitch;
    pfill.startY = startY;
    pfill.height = height;
    pfill.scanlinelist = scanlinelist;
//    FillPolygon(scanlinelist, startY, height, srcImg, dstImg);
    FillPolygon(pfill);

    if (scanlinelist)
        delete [] scanlinelist;
}

void GradientFillColor(
            int* gradientTable,
            int x0, int y0, int vx, int vy,
            const BitmapBufInfo *img)
{

    int len = vx*vx+vy*vy;

    _GRADFILL gfill;
    gfill.pDst = (UInt8*)img->address;
    gfill.nPitch = img->pitch;
    gfill.incx_16 = int(((long long int)(vx)<<24)/len);
    gfill.incy_16 = int(((long long int)(vy)<<24)/len);
    gfill.x0 = x0;
    gfill.y0 = y0;
    gfill.gradientTable = gradientTable;
    gfill.width = img->width;

    GradientFill(gfill);
}

